/*
	Copyright (c) 2007, ANYwebcam.com Pty Ltd. All rights reserved.

	The software in this package is published under the terms of the BSD style 
	license, a copy of which has been included with this distribution in the 
	license.txt file.
*/
package com.anywebcam.di.component
{
	import com.anywebcam.di.*;
	import com.anywebcam.di.component.*;
	import com.anywebcam.di.error.*;

	import flexunit.framework.TestCase;
	import flexunit.framework.TestSuite;

	public class InstanceComponentTest extends TestCase
	{
		public static function suite():TestSuite
		{
			var ts:TestSuite = new TestSuite();

			var tests:Array = 
			[
				'shouldReturnTheSetKey',
				'shouldReturnTheClassOfTheInstanceForType',
				'shouldReturnTheSameInstanceForEachCallToGetInstance',
			];

			tests.forEach( function( methodName:String, index:int, array:Array ):void
			{
				ts.addTest( new InstanceComponentTest( methodName ) );
			});

			return ts;
		}

		public function InstanceComponentTest( method:String )
		{
			super( method );
		}
		
		public function shouldReturnTheSetKey():void
		{
			var instance:Instance = new Instance();
			var component:DIComponent = new InstanceComponent( 'instance-test', instance );
			
			assertEquals( 'Expecting InstanceComponent::key to be the same as set in constructor', 'instance-test', component.key );
		}
		
		public function shouldReturnTheClassOfTheInstanceForType():void
		{
			var instance:Instance = new Instance();
			var component:DIComponent = new InstanceComponent( 'instance-test', instance );
			
			assertEquals( 'Expecting InstanceComponent::type to be a Class of Instance', Instance, component.type );
		}
		
		public function shouldReturnTheSameInstanceForEachCallToGetInstance():void
		{
			var instance:Instance = new Instance();
			var component:DIComponent = new InstanceComponent( 'instance-test', instance );
			
			var instanceOne:Instance = component.getInstance( null ) as Instance;
			var instanceTwo:Instance = component.getInstance( null ) as Instance;
			
			assertStrictlyEquals( 'Expecting multiple calls to InstanceComponent::getInstance to return the same instance', instanceOne, instanceTwo );
		}
	}
}

import com.anywebcam.di.*;
import com.anywebcam.di.component.*;

internal class Instance
{
	public function Instance()
	{
	}
}
